//
//  ChannelView.m
//  Bespoke
//
//  Created by Cheng on 12/10/24.
//
//

#import "ChannelView.h"
#import "AccountChannel.h"

#define SOCIAL_CHANNELID -2

#define LABEL_SHOW_ALL @"SHOW ALL"
#define LABEL_BESPOKE @"BESPOKE"
#define LABEL_BLOGS @"BLOGS"
#define LABEL_ALL_SOCIAL_MEDIA @"ALL SOCIAL MEDIA"
#define LABEL_FACEBOOK @"FACEBOOK"
#define LABEL_INSTAGRAM @"INSTAGRAM"
#define LABEL_TWITTER @"TWITTER"
#define LABEL_TUMBLR @"TUMBLR"

@implementation ChannelView
@synthesize Array_Channel, TVw_Channel;
@synthesize delegate;

- (void)initArray
{
    self.Array_Channel = [[NSMutableArray alloc] init];
    
    [self.Array_Channel addObject:[[AccountChannel alloc] InitChannel:SOCIAL_CHANNELID SetChannelName:LABEL_SHOW_ALL]];
    [self.Array_Channel addObject:[[AccountChannel alloc] InitChannel:SOCIAL_CHANNELID SetChannelName:LABEL_BESPOKE]];
    [self.Array_Channel addObject:[[AccountChannel alloc] InitChannel:SOCIAL_CHANNELID SetChannelName:LABEL_BLOGS]];
    [self.Array_Channel addObject:[[AccountChannel alloc] InitChannel:SOCIAL_CHANNELID SetChannelName:LABEL_ALL_SOCIAL_MEDIA]];
    [self.Array_Channel addObject:[[AccountChannel alloc] InitChannel:SOCIAL_CHANNELID SetChannelName:LABEL_FACEBOOK]];
    [self.Array_Channel addObject:[[AccountChannel alloc] InitChannel:SOCIAL_CHANNELID SetChannelName:LABEL_INSTAGRAM]];
    [self.Array_Channel addObject:[[AccountChannel alloc] InitChannel:SOCIAL_CHANNELID SetChannelName:LABEL_TWITTER]];
    [self.Array_Channel addObject:[[AccountChannel alloc] InitChannel:SOCIAL_CHANNELID SetChannelName:LABEL_TUMBLR]];
}

#pragma mark - UITableViewDelegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *ButtonCellIdentifier = @"ButtonCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ButtonCellIdentifier];
    
    UIView *bgColorView = [[UIView alloc] init];
    UIColor *UC_skyblue= [UIColor colorWithRed:206.0/255.0 green:235.0/255.0 blue:236.0/255.0 alpha:1.0];
    [bgColorView setBackgroundColor:UC_skyblue];
    
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ButtonCellIdentifier];
        cell.textLabel.font = [UIFont fontWithName:@"EamesCenturyModern-Regular" size:15];
        cell.textLabel.textColor = [UIColor darkGrayColor];
        [cell setSelectedBackgroundView:bgColorView];
    }
    cell.textLabel.text = ((AccountChannel *)[Array_Channel objectAtIndex:indexPath.row]).NS_ChannelName;
    
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [Array_Channel count];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate ChannelDidSelected:((AccountChannel *)[Array_Channel objectAtIndex:indexPath.row]).NS_ChannelName];
    [self.delegate uiViewTouched_Channel:NO ];
}

#pragma mark - Touches

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    if( point.x > 0 && point.x < self.frame.size.width && point.y > 0 && point.y < self.frame.size.height )
    {
        [delegate uiViewTouched_Channel:YES ];
        return YES;
    }
    
    [delegate uiViewTouched_Channel:NO ];
    return NO;
}

@end
